const Router = require('koa-router')
const {upload, upLoadImg} = require("../oss/oss");
const {auth} = require("../middleware/auth.middleware");

const commonRouter = new Router({prefix: '/common'});
commonRouter.post('/uploadImg', auth, upload.single('file'), async ctx => {
        console.log(ctx.file);
        try {
            const res = await upLoadImg(ctx.file.filename, ctx.file.path)
            ctx.body = {
                status: 0,
                data: res,
                msg: '上传成功'
            }
        } catch (e) {
            ctx.body = {
                status: 1,
                data: null,
                msg: '上传失败'
            }
        }

    }
)
;

commonRouter.get('/test', async ctx => {
    ctx.body = '想知道接口更新了没有'
})


module.exports = commonRouter
